package com.sptpc.demo.controller;

import com.sptpc.demo.service.IOrderService;
import com.sptpc.demo.vo.OrderWithItemsVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private IOrderService orderService;
//
//    @PostMapping("/")
//    public Order addNewOrder(@RequestBody AddOrderRequest request) {
//        log.info("订单信息:{}", request);
//        // AddOrderRequest -> Order
//        Order order = new Order();
//        BeanUtils.copyProperties(request, order);
//        orderService.addNewOrder(order, request.getItems());
//
//        return order;
//    }
//

    /**
     * get /order/{id}/
     *
     * @param id 订单号
     * @return 查询的订单信息
     */
    @GetMapping("/{id}")
    public OrderWithItemsVo getOrderByID(@PathVariable Long id) {
        return orderService.selectOrederById(id);
    }
    //get/ /order/{id}/{customer}

    /**
     * get /order/{id}/{customer}
     *
     * @param id       订单号
     * @param customer 用户名
     * @return 查询的订单信息
     */
    @GetMapping("/{id}/{customer}")
    public OrderWithItemsVo OrderWithByIdandCustomer(@PathVariable Long id, @PathVariable String customer) {
        return orderService.selectOrederByIdWithCustomer(id, customer);
    }

}
